﻿package frEngine.loaders.particleSub.particleInstance
{
    import flash.geom.*;
    import frEngine.math.*;

    public class RoundData extends MeshBase
    {
        private var _radius:Number;
        private var _segments:int;
        private var _radian:Number = 0;
        private var _rotate:Number = 0;
        private var _roteteOffset:Number = 1.5708;
        private var ve:Vector3D;
        private var normal:Vector3D;
        private var uv:Vector3D;

        public function RoundData(param1:Number = 150, param2:int = 12, param3:Number = 6.28319, param4:Quaternion = null)
        {
            this.ve = new Vector3D();
            this.normal = new Vector3D();
            this.uv = new Vector3D();
            super(0, 8, true, false);
            this._radius = param1;
            this._radian = param3;
            this._rotate = (-this._radian) / 2 - this._roteteOffset;
            this._segments = param2;
            this.createRound(param4);
            this.numVertex = this.vertexVector.length / this.sizePerVertex;
            return;
        }// end function

        private function createRound(param1:Quaternion) : void
        {
            var _loc_2:int = 0;
            var _loc_3:Number = NaN;
            var _loc_4:Number = NaN;
            var _loc_5:Number = NaN;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            vertexVector = new Vector.<Number>;
            indexVector = new Vector.<uint>;
            var _loc_8:* = this._segments;
            _loc_3 = 0;
            if (this._radius > 0)
            {
                vertexVector.push(0, 0, 0, 0, 0, 0, 0, 0);
                _loc_7 = vertexVector.length / sizePerVertex - 1;
                _loc_3 = 0;
                while (_loc_3 <= _loc_8)
                {
                    
                    var _loc_9:* = Math.cos(_loc_3 / _loc_8 * this._radian + this._rotate) * this._radius;
                    this.ve.x = Math.cos(_loc_3 / _loc_8 * this._radian + this._rotate) * this._radius;
                    this.uv.x = _loc_9;
                    var _loc_9:* = (-Math.sin(_loc_3 / _loc_8 * this._radian + this._rotate)) * this._radius;
                    this.ve.z = (-Math.sin(_loc_3 / _loc_8 * this._radian + this._rotate)) * this._radius;
                    this.uv.z = _loc_9;
                    var _loc_9:int = 0;
                    this.ve.y = 0;
                    this.uv.y = _loc_9;
                    if (param1 != null)
                    {
                        param1.rotatePoint(this.ve, this.ve);
                    }
                    vertexVector.push(this.ve.x, this.ve.y, this.ve.z, this.uv.x / this._radius * 0.5, this.uv.z / this._radius * 0.5, this.normal.x, 1, this.normal.z);
                    _loc_3 = _loc_3 + 1;
                }
            }
            _loc_2 = 0;
            _loc_3 = 0;
            if (this._radius > 0)
            {
                _loc_3 = 1;
                while (_loc_3 < (_loc_8 + 1))
                {
                    
                    var _loc_9:* = _loc_2 + 1;
                    indexVector[_loc_9] = _loc_7;
                    var _loc_10:* = _loc_2 + 1;
                    indexVector[_loc_10] = _loc_7 + _loc_3;
                    var _loc_11:* = _loc_2 + 1;
                    indexVector[_loc_11] = _loc_7 + _loc_3 + 1;
                    _loc_3 = _loc_3 + 1;
                }
            }
            return;
        }// end function

        public function get radius() : Number
        {
            return this._radius;
        }// end function

        public function get segments() : int
        {
            return this._segments;
        }// end function

    }
}
